package com.houxy.service.impl;

import com.houxy.repository.mapper.HospitalMapper;
import com.houxy.repository.model.entity.Hospital;
import com.houxy.service.HospitalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Liuym
 * @date 2019/3/18 15:53
 * @describe：
 */
@Service("hospitalService")
public class HospitalServiceImpl implements HospitalService {

    @Autowired
    private HospitalMapper hospitalMapper;

    @Override
    public boolean addHospital(Hospital hospital) {
        hospital.setIsDelete(0);
        int insert = hospitalMapper.insertSelective(hospital);
        if (insert > 0) {
            return true;
        }
        return false;
    }

    @Override
    public List<Hospital> findAll() {
        return hospitalMapper.findAll();
    }

    @Override
    public boolean deleteHospital(int hospitalId) {
        Hospital hospital = findById(hospitalId);
        if (hospital != null) {
            hospital.setIsDelete(1);
        }
        int update = hospitalMapper.updateByPrimaryKeySelective(hospital);
        if (update > 0) {
            return true;
        }
        return false;
    }

    @Override
    public Hospital findById(int hospitalId) {
        return hospitalMapper.selectByPrimaryKey(hospitalId);
    }
}
